import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import 'rxjs/add/operator/toPromise';
import {HttpServies} from '../../providers/http-servies';

import {ForgetPage} from "../forget/forget";
import {HomePage} from '../home/home';

@Component({
  selector: 'page-contact',
  templateUrl: 'contact.html',
  providers:[HttpServies]
})
export class ContactPage {
  userInfo = {
    'mobile': '',
    'password': '',

  }
  constructor(public navCtrl: NavController, public navParams: NavParams, private http: HttpServies) {

  }
  intPage() {
    this.navCtrl.push(ForgetPage);
  }
  /*
   * 登录方法
   * */
  checkInfo() {
    if (!this.userInfo.mobile || !this.userInfo.password) {
      this.http.showErro("请输入完整信息");
      return;
    }
    if (this.userInfo.mobile) {
      var myreg = /^1[3|4|5|7|8|9]\d{9}$/;
      if (!myreg.test(this.userInfo.mobile)) {
        this.http.showErro("请输入正确的手机号码");
        return;
      }
    }
    var param = "mobile=" + this.userInfo.mobile + "&password=" + this.userInfo.password;
    this.http.httpPost('/home/index/login', param)
        .then(res => {
          if (res && res.code ==1) {
            localStorage.setItem("mobile",this.userInfo.mobile);
            localStorage.setItem("token",res.data);
            this.navCtrl.push(HomePage);
            this.http.showErro(res.msg);
          }else {
            this.http.showErro(res.msg);
          }
        })
  }
}
